<?php

namespace App\Exports;

use App\Models\EquipmentCompany;
use App\Models\Report;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;


class EquipmentCompanyExport implements FromCollection,WithHeadings,WithMapping
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        $query=EquipmentCompany::query();
        if (isset($this->filters['ids'])) {
            $query->whereIn('id', explode(',',$this->filters['ids']));
        }
        return $query->get();
    }
    public function headings(): array
    {
        return [
            '厂家名称',
            '厂家负责人',
            '平台ID',
            '平台密钥',
            '厂家状态',
            '创建时间',
            // ... 其他列标题
        ];
    }

    public function map($equipmentcompany): array
    {
        // 假设订单有 id 和 total 字段
        $orderData[] = [
            $equipmentcompany['name'],
            $equipmentcompany['user_name'],
            $equipmentcompany['id'],
            $equipmentcompany['key'],
            $equipmentcompany['status'],
            $equipmentcompany['created_at'],

        ];
        // 展开订单数据，以便每行都有用户信息和对应的订单信息
        return array_merge(...$orderData);
    }
}
